package chess;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import chesskers.GamePiece;

public class PawnPiece extends ChessPiece{
	
	public boolean canPromote;
	public boolean canLeftEnpassante;
	public boolean canRightEnpassante;
	
	public PawnPiece(boolean black, int x_, int y_) {
		super(black, x_, y_);
				
		canPromote = false;
		
		if (black){
			movePossibilities = new int[][][]{{{0, 1}, {0, 2}}};
			attackPossibilities = new int[][][]{{{1, 1}}, {{-1, 1}}};
		}else{
			movePossibilities = new int[][][]{{{0, -1}, {0, -2}}};
			attackPossibilities = new int[][][]{{{1, -1}}, {{-1, -1}}};
		}
	}
	
	public GamePiece[][] moveTo(int x_, int y_, GamePiece[][] board){
		board = super.moveTo(x_, y_, board);
		if (isBlack){
			movePossibilities = new int[][][]{{{0, 1}}};
		}else{
			movePossibilities = new int[][][]{{{0, -1}}};
		}
		return board;
	}
	
	public String getName(){
		return "pawn";
	}
	
	@Override 
	public List<SpecialMove> getSpecialMovePossibilities() {
		List<SpecialMove> specialMoves = new ArrayList<SpecialMove>();
		if (canPromote)
			if (isBlack)
				specialMoves.add(new SpecialMove("pawnpromote", new Point(x, y), new Point(x, y+1), SpecialMoveType.promote));
			else 
				specialMoves.add(new SpecialMove("pawnpromote", new Point(x, y), new Point(x, y-1), SpecialMoveType.promote));
		if (canLeftEnpassante)
			if (isBlack)
				specialMoves.add(new SpecialMove("leftenpassante", new Point(x, y), new Point(x-1, y-1), new Point(x-1, y), SpecialMoveType.attack));
			else 
				specialMoves.add(new SpecialMove("leftenpassante", new Point(x, y), new Point(x-1, y+1), new Point(x-1, y), SpecialMoveType.attack));
		if (canRightEnpassante)
			if (isBlack)
				specialMoves.add(new SpecialMove("righttenpassante", new Point(x, y), new Point(x+1, y-1), new Point(x-1, y), SpecialMoveType.attack));
			else 
				specialMoves.add(new SpecialMove("righttenpassante", new Point(x, y), new Point(x+1, y+1), new Point(x-1, y), SpecialMoveType.attack));
		if (specialMoves.size() > 0)
			canSpecialMove = true;
		return specialMoves;
	}
}
